 /*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

 /**
 * Project  : AvatarHelper
 * Package  : net.solosky.avatarhelper.api
 * File     : Friend.java
 * Author   : solosky < solosky772@qq.com >
 * Created  : 2011-10-23
 * License  : Apache License 2.0 
 */
package net.solosky.easyavatar.api;

import net.solosky.easyavatar.api.util.PinYinUtil;

/**
 *
 * 朋友
 *
 * @author solosky <solosky772@qq.com>
 *
 */
public class Friend {
	/**编号，唯一*/
	private String fid;
	/**所属组ID*/
	private String gid;
	/**昵称，昵称是一定存在的*/
	private String nick;
	/**真实姓名，不一定存在*/
	private String name;
	/**名字的拼音*/
	private String pinyin;
	/**头像*/
	private Avatar avatar;
	
	public Friend() {
		super();
		avatar = new Avatar(); 
	}
	public String getFid() {
		return fid;
	}
	public void setFid(String fid) {
		this.fid = fid;
	}
	public String getGid() {
		return gid;
	}
	public void setGid(String gid) {
		this.gid = gid;
	}
	public String getNick() {
		return nick;
	}
	public void setNick(String nick) {
		this.nick = nick;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public Avatar getAvatar() {
		return avatar;
	}
	public void setAvatar(Avatar avatar) {
		this.avatar = avatar;
	}
	
	public String getDisplay(){
		if(!isEmpty(name)) return name;
		if(!isEmpty(nick)) return nick;
		return fid;
	}
	
	public String getPinyin() {
		if(pinyin==null){
			pinyin = getDisplay()!=null ? PinYinUtil.getPinYin(getDisplay()):"";
		}
		return pinyin;
	}
	private boolean isEmpty(String s){
		return s==null || s.length()==0 || s.trim().length()==0;
	}
	@Override
	public String toString() {
		return "Friend [fid=" + fid + ", gid=" + gid + ", getDisplay()="
				+ getDisplay() + "]";
	}
	
	
}
